<?php
namespace Org;
use Think\Controller;
class Admin_autoload extends Controller{
    //ThinkPHP的构造函数
    public function _initialize() {
        header("Content-type:text/html;charset=utf-8");
        //$this->maintaining(); //维护中
        //如果未登录，则跳转到登录页面
        if(!session('admin_id')){
            echo "<script>window.location.href='/login'</script>";exit;
        }
        //$this->admin_info=$this->get_admin_info();
        //$this->assign('admin_info',$this->admin_info);
        //print_r($this->admin_info);exit;
    }
    //维护中
    private function maintaining(){
        echo '网站维护中，造成不便，敬请谅解,预计2016.5.26 17:15重新开启';exit;
    }
    //获取 后台用户信息
    private function get_admin_info(){
        //设置 admin_info
        if(session('admin_id')){
            $admin_id=session('admin_id');
        }
        if(session('admin_group_id')){
            $admin_group_id=session('admin_group_id');
        }
        if(cookie('admin_id')){
            $admin_id==cookie('admin_id');
        }
        if(cookie('admin_group_id')){
            $admin_group_id=cookie('admin_group_id');
        }
        if($admin_id!=''){
            $admin_info['admin_id']=$admin_id;
            $admin_info['admin_name']=M('Admin','think_',C('DB_CONFIG'))->where('admin_id='.$admin_id)->getField('admin_name');
        }
        if($admin_group_id!=''){
            $admin_info['admin_group_id']=$admin_group_id;
            $admin_info['admin_group_name']=M('AdminGroup','think_',C('DB_CONFIG'))->where('admin_group_id='.$admin_group_id)->getField('admin_group_name');
        }


        //dump(cookie());exit;
        //dump($admin_info);exit;
        return $admin_info;
    }

}